/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/idenger">idenger</a> All rights reserved.
 */
package com.idenger.modules.edu.web.project;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.idenger.common.config.Global;
import com.idenger.common.utils.StringUtils;
import com.idenger.common.web.BaseController;
import com.idenger.modules.edu.entity.project.EduProjectCourse;
import com.idenger.modules.edu.service.project.EduProjectCourseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.idenger.common.persistence.Page;

/**
 * 项目课程关联Controller
 * @author chenlin
 * @version 2017-12-04
 */
@Controller
@RequestMapping(value = "${adminPath}/edu/project/eduProjectCourse")
public class EduProjectCourseController extends BaseController {

	@Autowired
	private EduProjectCourseService eduProjectCourseService;
	
	@ModelAttribute
	public EduProjectCourse get(@RequestParam(required=false) String id) {
		EduProjectCourse entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eduProjectCourseService.get(id);
		}
		if (entity == null){
			entity = new EduProjectCourse();
		}
		return entity;
	}
	
	@RequiresPermissions("edu:project:eduProjectCourse:view")
	@RequestMapping(value = {"list", ""})
	public String list(EduProjectCourse eduProjectCourse, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EduProjectCourse> page = eduProjectCourseService.findPage(new Page<EduProjectCourse>(request, response), eduProjectCourse); 
		model.addAttribute("page", page);
		return "modules/edu/project/eduProjectCourseList";
	}

	@RequiresPermissions("edu:project:eduProjectCourse:view")
	@RequestMapping(value = "form")
	public String form(EduProjectCourse eduProjectCourse, Model model) {
		model.addAttribute("eduProjectCourse", eduProjectCourse);
		return "modules/edu/project/eduProjectCourseForm";
	}

	@RequiresPermissions("edu:project:eduProjectCourse:edit")
	@RequestMapping(value = "save")
	public String save(EduProjectCourse eduProjectCourse, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eduProjectCourse)){
			return form(eduProjectCourse, model);
		}
		eduProjectCourseService.save(eduProjectCourse);
		addMessage(redirectAttributes, "保存项目课程关联成功");
		return "redirect:"+ Global.getAdminPath()+"/edu/project/eduProjectCourse/?repage";
	}
	
	@RequiresPermissions("edu:project:eduProjectCourse:edit")
	@RequestMapping(value = "delete")
	public String delete(EduProjectCourse eduProjectCourse, RedirectAttributes redirectAttributes) {
		eduProjectCourseService.delete(eduProjectCourse);
		addMessage(redirectAttributes, "删除项目课程关联成功");
		return "redirect:"+Global.getAdminPath()+"/edu/project/eduProjectCourse/?repage";
	}
	


}